<template>
  <div class="viewContain">
    <el-form :model="listQuery" size="small" label-width="100px">
      <el-row>
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 4 }" :xl="{ span: 4 }">
          <el-form-item label="版本名称 :">
            <el-input
              v-model="listQuery.name"
              placeholder="请输入内容"
              clearable
              style="max-width:200px"
              @keyup.enter.native="handleSearch"
            />
          </el-form-item>
        </el-col>
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 4 }" :xl="{ span: 4 }">
          <el-form-item label="版本号 :">
            <el-input
              v-model="listQuery.version"
              placeholder="请输入内容"
              clearable
              style="max-width:200px"
              @keyup.enter.native="handleSearch"
            />
          </el-form-item>
        </el-col>
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 4 }" :xl="{ span: 4 }">
          <el-form-item label="状态 :">
            <el-select v-model="listQuery.status" placeholder="请选择" clearable>
              <el-option
                v-for="item in state"
                :key="item.code"
                :label="item.codeDesc"
                :value="item.code"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 8 }" :xl="{ span: 8 }">
          <el-form-item label="发布时间段 :">
            <el-date-picker
              v-model="listQuery.time"
              size="small"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              unlink-panels
            />
          </el-form-item>
          <input type="hidden" name="beginTime" value="listQuery.beginTime">
          <input type="hidden" name="endTime" value="listQuery.endTime">
        </el-col>
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 4 }" :xl="{ span: 4 }">
          <el-form-item label-width="100px">
            <el-button size="mini" style="margin-left:10px" type="primary" @click="handleSearch">查询</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table
      ref="table"
      v-loading="loading"
      fit
      stripe
      :data="tableData"
      border
      size="mini"
      class="tableClass"
    >
      <el-table-column align="center" label="序号" type="index" width="50" fixed="left">
        <template slot-scope="scope">
          <span>{{ (listQuery.pageNo - 1) * listQuery.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="name" align="center" label="版本名称" width="150" fixed="left" />
      <el-table-column prop="version" align="center" label="版本号" width="60" fixed="left" />
      <el-table-column prop="deviceNo" align="center" label="设备终端编号" width="150" />
      <el-table-column prop="deviceType" align="center" label="设备类型" width="150" />
      <el-table-column prop="createTime" align="center" label="新增时间" width="180" />
      <el-table-column prop="status" align="center" label="更新状态" width="80" />
      <el-table-column prop="createUser" align="center" label="操作员账号" width="100" />
      <el-table-column prop="pushNum" align="center" label="推送次数" />
      <el-table-column prop="modUser" align="center" label="修改人" />
      <el-table-column prop="modTime" align="center" label="修改时间" width="180" />
      <el-table-column prop="updateTime" align="center" label="更新时间" width="180" />
      <el-table-column prop="updateType" align="center" label="更新类型" width="100" />
      <el-table-column prop="remark" align="center" label="备注" width="80" show-overflow-tooltip="true" />
      <el-table-column align="center" label="操作" width="100">
        <template slot-scope="scope">
          <el-button class="text-button" size="mini" @click="handleDetail(scope.row)">详细</el-button>
          <el-button class="text-button el-button--danger" size="mini" @click="handleDelVersion(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 详情 -->
    <el-dialog
      :title="title"
      :visible.sync="dialogVisble"
      :close-on-click-modal="false"
      width="400px"
    >
      <div class="detailInfo">
        <p>版本号:&nbsp;&nbsp;{{ detailInfo.version }}</p>
        <p>版本名称:&nbsp;&nbsp;{{ detailInfo.name }}</p>
        <p>添加人:&nbsp;&nbsp;{{ detailInfo.createUser }}</p>
        <p>添加时间:&nbsp;&nbsp;{{ detailInfo.createTime }}</p>
        <p>设备终端编号:&nbsp;&nbsp;{{ detailInfo.deviceNo }}</p>
        <p>设备类型:&nbsp;&nbsp;{{ detailInfo.deviceType }}</p>
        <p>完成时间:&nbsp;&nbsp;{{ detailInfo.finishTime }}</p>
        <p>推送次数:&nbsp;&nbsp;{{ detailInfo.pushNum }}</p>
        <p>备注:&nbsp;&nbsp;{{ detailInfo.remark }}</p>
        <p>修改人:&nbsp;&nbsp;{{ detailInfo.modUser }}</p>
        <p>修改时间:&nbsp;&nbsp;{{ detailInfo.modTime }}</p>
        <p>更新状态:&nbsp;&nbsp;{{ detailInfo.status }}</p>
        <p>更新时间:&nbsp;&nbsp;{{ detailInfo.updateTime }}</p>
        <p>更新类型:&nbsp;&nbsp;{{ detailInfo.updateType }}</p>
      </div>
    </el-dialog>
    <pagination
      :total-count="totalCount"
      :page.sync="listQuery.pageNo"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { commonMixin } from '@v/mixin/commonMixin.js'
import ComApiUrl from '@a/comomApi.js'
import pagination from '@/components/pagination/index.vue'
import { getState, deleteUpdateList } from '@a/software/updateQuene.js'

export default {
  // eslint-disable-next-line vue/no-unused-components
  components: { pagination },
  mixins: [commonMixin],
  data() {
    return {
      comApiUrlList: new ComApiUrl('/version/api/v2/versionQueue/list'),
      listQuery: {},
      checkResult: {},
      loading: false,
      state: [],
      title: '版本更新详情',
      dialogVisble: false,
      detailInfo: {
        createTime: '',
        createUser: '',
        deviceNo: '',
        deviceType: '',
        finishTime: '',
        pushNum: '',
        remark: '',
        returnCode: '',
        status: '',
        updateTime: '',
        updateType: '',
        modTime: '',
        modUser: '',
        name: '',
        version: ''
      },
      tableData: [
        {
          name: '',
          version: '',
          createTime: '',
          status: '',
          processTime: '',
          description: ''
        }
      ]
    }
  },
  mounted() {
    this.getList()
    getState().then(res => {
      if (res.code === 0) {
        this.state = res.data
      }
    })
  },
  methods: {

    getList() {
      this.getInfo()
    },

    // 查询
    handleSearch() {
      // 将时间范围存成两个变量,有才存储,没有值的时候,对象的值为空
      this.listQuery.beginTime = ''
      this.listQuery.endTime = ''
      if (this.listQuery.time !== null && this.listQuery.time !== undefined && this.listQuery.time.length > 0) {
        const beginTime = this.listQuery.time[0]
        const endTime = this.listQuery.time[1]
        this.listQuery.beginTime = beginTime
        this.listQuery.endTime = endTime
        console.log('begintime:::' + beginTime + 'endtime::' + endTime)
        console.log('listQuery.beginTime :' + this.listQuery.beginTime + 'listQuery.endTime :' + this.listQuery.endTime)
      }
      this.getList()
    },
    // 详情
    handleDetail(row) {
      this.dialogVisble = true
      this.detailInfo = row
    },
    // 删除
    handleDelVersion(id) {
      var msg = '您确定要删除此条记录吗？\n\n请确认！'
      if (confirm(msg) === true) {
        deleteUpdateList(id).then((res) => {
          if (res.code === 0) {
            this.$message({
              type: 'success',
              message: '该记录已被成功删除'
            })
            this.getList()
          } else {
            this.$message({
              type: 'error',
              message: res.msg
            })
          }
        })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.detailInfo {
  width:300px;
  margin:10px auto;
}
.detailInfo p{
  margin-top:5px;
}
.tableClass{
   ::v-deep .el-table__fixed{
    height: 100% !important;   //设置高优先，以覆盖内联样式
  }
}
</style>
